/**
 * @author zhouheng
 * @date 2022年03月05日 15:50
 */

package com.gulimall.search.gulimallsearch.controller;

import com.gulimall.search.gulimallsearch.service.SearchService;
import com.gulimall.search.gulimallsearch.vo.SearchParam;
import com.gulimall.search.gulimallsearch.vo.SearchResult;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SearchController {

    @Autowired
    SearchService searchService;

    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request){

//         获取路径原生的查询属性
        searchParam.set_queryString(request.getQueryString());
        // ES中检索到的结果 传递给页面
        SearchResult result = searchService.search(searchParam);
        model.addAttribute("result", result);
        System.out.println(result);
        return "list";
    }
}
